package com.qf.dao.impl;

import com.qf.dao.DeveloperDao;
import com.qf.dao.ProjectDao;
import com.qf.pojo.Developer;
import com.qf.pojo.Project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description: 公用常量
 * @Data: 2022/9/2 15:13
 * @Pacakge: com.qf.dao.impl
 * @ClassName: ProjectDaoImpl
 * @Author: fan
 */
@Repository("productDao")//持久层
public class ProjectDaoImpl implements ProjectDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private DeveloperDao developerDao;
    /**
     * 查询project表的时候需要关联查询developer。
     * @return project工程表以及developer表
     */
    @Override
    public List<Project> findAllProject() {
        List<Project> list = jdbcTemplate.query(
                "select * from project left join  developer on project.did=developer.did where  project.status=1"
                ,new BeanPropertyRowMapper<Project>(Project.class));
        return list;
    }
    /**
     * 根据pid查询项目
     * @param pid 项目编号
     * @return 项目列表
     */
    @Override
    public List<Project> findProjectByPid(Integer pid) {
        return jdbcTemplate.query(
                "select * from project where pid = ?"
                ,new BeanPropertyRowMapper<Project>(Project.class)
                ,pid
        );
    }
}
